package com.example.healthcondition.mapper;

import com.example.healthcondition.entity.DietPlans;
import org.apache.ibatis.annotations.*;

import java.util.Map;

@Mapper
public interface DietPlansMapper {
    @Select("SELECT * FROM dietplans WHERE user_id = #{userId} ORDER BY start_date DESC LIMIT 1")
    Map<String,Object> findLatestByUserId(@Param("userId") Integer userId);


    @Insert("INSERT INTO dietplans (user_id, plan_name, start_date, end_date, daily_calories, description) " +
            "VALUES (#{userId}, #{planName}, #{startDate}, #{endDate}, #{dailyCalories}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "planId")
    int insertDietPlan(DietPlans dietPlan);


}
